package com.tzstcl.gen.util;

import java.io.File;

/**
 * Created by an on 2016/9/27.
 */
public class Folder {

    private static String baseFolder = "\\src\\main\\";
    private static String classFolder = "java\\";
    private static String xmlFolder = "resources\\mybatis\\";
    private static String viewFolder = "resources\\templates\\admin\\";

    /**
     * 目录生成
     *
     * @param folderName 路径名称
     * @param type       路径类型，1：class，2：xml，3：页面
     * @return
     */
    public String folder(String folderName, String type) {
        String path = folderName.replace(".", "\\");
        try {
            File basefile = new File("d:");
            File file2 = new File("e:");
            File file3 = new File("f:");
            File file4 = new File("g:");

            if (basefile.exists()) {

            } else if (file2.exists()) {
                basefile = file2;
            } else if (file3.exists()) {
                basefile = file3;
            } else if (file4.exists()) {
                basefile = file4;
            }
            String folder = classFolder;
            switch (type) {
                case "1":
                    folder = classFolder;
                    break;
                case "2":
                    folder = xmlFolder;
                    break;
                case "3":
                    folder = viewFolder;
                    break;
            }
            File dir = new File(basefile + baseFolder + folder + path);
            dir.mkdirs();
            return dir.toString();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return "error";
    }


}
